﻿<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="ParamConfig.aspx.cs" Inherits="JKF.Web.Sys.Param.ParamConfig" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml">
<head id="Head1" runat="server">
    <title></title>
    <script src="../../js/jquery.js" type="text/javascript"></script>
<%--    <link href="../../css/common_v2.css" rel="stylesheet" type="text/css" />
    <link href="../../css/tool.css" rel="stylesheet" type="text/css" />
    <link href="../../images_h8_nav/h8_nav_v2.css" rel="stylesheet" type="text/css" />--%>
    <link href="../../App_Themes/Theme2/Include.css"   rel="stylesheet" type="text/css" />

    <script type="text/javascript" language="javascript" src="../../js/jquery.js"></script>
    <script type="text/javascript" src="../../js/DatePicker/WdatePicker.js"></script>
    <script type="text/javascript" src="../../js/jquery.rchis.js"></script>
    <script type="text/javascript" src="../../js/json2.js"></script>
    <script type="text/javascript" language="javascript" src="../../js/jquery.composition.js"></script>
</head>
<body>
    <div class="warrper_body"  >  
        <div class="index" style=" overflow:hidden;margin-left:100px; margin-right:20px">
            <div class="common_search" style="width:970px;" >
                    <div class="l_h45">  
                    参数名称：<input id="text_search" type="text" style="width: 200px;" />
                    <input id="bt_search" type="button" class="common_btn_search"  class="btn77" />
                 </div>
            </div>
           
            <div class="l_h14"></div>

            <div class="index_table">
                <div style="width: 985px; height: 25px; overflow: hidden;">
                    <table  style="width: 985px;" class="common_table">
                        <thead>
                            <tr>
                                <th style="width:200px;padding-left: 3px;"> 参数编码</th>
                                <th style="width:200px;padding-left: 3px;"> 参数名称</th>
                                <th style="width:370px;padding-left: 3px;"> 参数意义描述</th>
                                <th style="width:200px;padding-left: 3px;"> 参数值</th>
                                <th style="width:15px"></th>
                            </tr>
                        </thead>
                    </table>
                </div>

                <div style="width: 970px; height: 280px; overflow-y:auto;overflow-x:hidden; margin-top: 0px;">
                    <table  style="width: 970px;" id="tb" class="common_table" width="100%" trheight="31">
                        <thead  style="display:none" >
                            <tr>
                                <th style="width:200px;padding-left: 3px;"> 参数编码</th>
                                <th style="width:200px;padding-left: 3px;"> 参数名称</th>
                                <th style="width:370px;padding-left: 3px;"> 参数意义描述</th>
                                <th style="width:200px;padding-left: 3px;"> 参数值</th>
                               
                            </tr>                 
                        </thead>
                        <tbody  id="tb_main" >     
                       
                                 
                        </tbody>
                    </table>
                </div>
             </div>
          <div class="pop_btn" style=" margin-top:4px">
             <input  id="btnSavePerson" type="button" class="common_btn_save mr30 mb25" value=" " />
         </div>
        </div>    

    

   </div>  

    
    <script type="text/javascript" language="javascript">
    
        var AppPath = '<%=AppPath %>';
        var Params = null;
        var updata_mode = null;
        $(document).ready(function () {
            $("#bt_search").click(function () {
                $.post(AppPath + "/do/Sys/SysParamValue.do",
                        { op_type: "Select", op_child_type: "GetParaList", SearchText: $.trim($("#text_search").val()) },
                        function (json) {
                            if (json.MessageCode == "ok") {
                                bindParam(json); //绑定参数
                                limitScale(); //绑定范围
                                bindParamValue(); //绑定参数值
                            }
                            else {
                                alert(json.Message);
                                $("#btnSavePerson").hide();
                            };
                        }, "json"
                );
                /* 根据系统参数key 取参数值
                        $.post(AppPath + "/do/Sys/SysParamValue.do", { op_type: "Select", op_child_type: "GetParaValueByKey", paramKey: "FILTER_HEAD_DAY" },
                            function (json) {
                                if (json.MessageCode == "ok")
                                    json.Message;
                                else 
                                    alert(json.Message);
                            }, "json");*/
            });

            function bindParam(json) {
                $("#tb_main").empty();
                Params = json.Data;
                var str = "";
                for (var i = 0; i < Params.length; i++) {
                    str += "<tr>";
                    str += "    <td style='width:200px'>" + Params[i].PARAM_KEY + "</td>";
                    str += "    <td style='width:200px'>"
                               + (Params[i].PARAM_SCOPE == "1" ? "<font color='red'>[全局]</font> " : "<font color='blue'>[机构]</font> ")
                               + Params[i].NAME + "</td>";
                    str += "    <td style='width:370px'>" + Params[i].MEANING + "</td>";
                    var str_temp = "";
                    if (Params[i].VAL_TYPE == "1") { //为数字类型
                        str_temp = "<input type='text' value='"
                                        + (Params[i].VAL_DEFAULT == null ? "" : Params[i].VAL_DEFAULT) + "' " //存在默认值则绑定默认值
                                        + "  id='" + Params[i].PARAM_KEY + "' maxlength=" + (Params[i].VAL_PRECISION + Params[i].VAL_SCALE)
                                        + "  VAL_TYPE='" + Params[i].VAL_TYPE + "' VAL_SCALE = " + Params[i].VAL_SCALE + " />";
                    }
                    else if (Params[i].VAL_TYPE == "2") { //时间类型
                        str_temp = "<input type='text' id='" + Params[i].PARAM_KEY + "' "
                                        + " onclick='WdatePicker({dateFmt:\"yyyy-MM-dd HH:mm:ss\"});'"
                                        + " onfocus='WdatePicker({dateFmt:\"yyyy-MM-dd HH:mm:ss\"});' VAL_TYPE='" + Params[i].VAL_TYPE + "' />";
                    }
                    else if (Params[i].VAL_TYPE == "3") { //bool值
                        str_temp = "<input type='text' value='" + (Params[i].VAL_DEFAULT == null ? "" : Params[i].VAL_DEFAULT) + "' "
                                    + " id='" + Params[i].PARAM_KEY + "' maxlength=1 VAL_TYPE='" + Params[i].VAL_TYPE + "' />";
                    }
                    else if (Params[i].VAL_TYPE == "4") {//4 其他参数值(表示为字符串形式)
                        str_temp = "<input type='text' value='" + (Params[i].VAL_DEFAULT == null ? "" : Params[i].VAL_DEFAULT) + "' "
                                    + "' id='" + Params[i].PARAM_KEY + "' maxlength=" + Params[i].VAL_SIZE
                                    + " VAL_TYPE='" + Params[i].VAL_TYPE + "' />";
                    }
                    else {
                        str_temp = "";
                    }

                    str += "<td style='width:200px'>" + str_temp + "</td>";

                    str += "</tr>";
                }
                $("#tb_main").append(str);
            }

            function limitScale() {
                $("#tb_main").find("input").each(function () {
                    if ($(this).attr("VAL_TYPE") == "1") { //为数字类型
                        $(this).forceNumber({
                            min: 0,
                            max: 18446744073709551615, // 2^64 - 1
                            scale: $(this).attr("VAL_SCALE")                   // decimal places
                        });
                    }

                    if ($(this).attr("VAL_TYPE") == "3") {  // bool值 限定值能为0 ,1
                        $(this).forceNumber({
                            min: 0,
                            max: 1, // 2^64 - 1
                            scale: 0                   // decimal places
                        });
                    }
                });
            }

            function bindParamValue() {
                $.post(AppPath + "/do/Sys/SysParamValue.do",
                    { op_type: "Select", op_child_type: "GetParaValue" },
                    function (json) {
                        if (json.MessageCode == "ok") {
                            var PARAM_VALUES = json.Data.Data;
                            updata_mode = json.Data.paramaMode;
                            for (var i = 0; i < PARAM_VALUES.length; i++) {
                                $("#tb_main").find("input").each(function () {
                                    if ($(this).attr("ID") == PARAM_VALUES[i].PARAM_KEY) {
                                        if ($(this).attr("VAL_TYPE") == "2") //为日期类型
                                            $(this).val(PARAM_VALUES[i].VAL_DATE);
                                        else
                                            $(this).val(PARAM_VALUES[i].VAL);
                                    }
                                });
                            }
                        }
                        else {
                            alert(json.Message);
                            $("#btnSavePerson").hide();
                        }

                    }, "json"
            );
            }


            $("#btnReturn").click(function () {
                window.location.href = $("#btnReturn").attr("href");
            });

            $("#bt_search").click();

            $("#btnSavePerson").click(function () {
                var Sys_Param_Value = new Array();

                $("#tb_main").find("input").each(function () {
                    var tempmode = $.extend(true, {}, updata_mode);
                    tempmode.PARAM_KEY = $(this).attr("id");
                    tempmode.VAL_TYPE = $(this).attr("VAL_TYPE");
                    tempmode.VALUE = $(this).val();
                    Sys_Param_Value.push(tempmode);
                });

                $.post(AppPath + "/do/Sys/SysParamValue.do",
                       { op_type: "Update", op_child_type: "UpdataParam", Params: JSON.stringify(Sys_Param_Value) },
                       function (json) {
                           if (json.MessageCode == "ok") {
                               alert("保存成功！");
                           }
                           else {
                               alert(json.Message);
                           }

                       }, "json");
            });
        });
       
    </script>

</body>
</html>
